package com.lg.domain;

import com.lg.spring.ioc.common.City;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.beans.factory.BeanNameAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User implements BeanNameAware {
    private Long id;
    private String name;
    private Integer age;
    private City city;

    /**
     * 当前 Bean 的名称
     */
    private transient String beanName;

    public  User(String name){
        this.name = name;
    }
    @Override
    public int hashCode(){
        return 1;
    }

    @Override
    public boolean equals(Object obj) {
        return false;
    }

    public static User createUser() {
        User user = new User();
        user.setId(1L);
        user.setName("staticUser");
        return user;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
        System.out.println("User初始化前 回调BeanNameAware接口");
    }

    @PostConstruct
    public void init() {
        System.out.println("User Bean [" + beanName + "] 初始化...");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("User Bean [" + beanName + "] 销毁中...");
    }


}
